/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import type { Reducer } from 'umi';

export type WinSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
export interface GlobalModelState {
  collapsed?: boolean;
  iframeFullScreen?: boolean;
  winSize?: WinSize;
  pathname?: string;
}

export interface GlobalModelType {
  namespace: 'global';
  state: GlobalModelState;
  reducers: {
    changeLayoutCollapsed: Reducer<GlobalModelState>;
    changeIframeFullScreen: Reducer<GlobalModelState>;
    changeWinSize: Reducer<GlobalModelState>;
    changePageTabs: Reducer<GlobalModelState>;
  };
}

const GlobalModel: GlobalModelType = {
  namespace: 'global',

  state: {
    collapsed: false,
    iframeFullScreen: false,
  },

  reducers: {
    changeLayoutCollapsed(state = { collapsed: true }, { payload }): GlobalModelState {
      return {
        ...state,
        collapsed: payload,
      };
    },
    changeIframeFullScreen(state = { iframeFullScreen: false }, { payload }): GlobalModelState {
      return {
        ...state,
        iframeFullScreen: payload,
      };
    },
    changeWinSize(state = { winSize: 'xxl' }, { payload }): GlobalModelState {
      return {
        ...state,
        winSize: payload,
      };
    },
    changePageTabs(state = { pathname: '' }, { payload }): GlobalModelState {
      return {
        ...state,
        pathname: payload,
      };
    },
  },
};

export default GlobalModel;
